const { ccclass, property } = cc._decorator;

@ccclass
export default class Player extends cc.Component {

    onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.handleTouchStart, this)
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.handleTouchMove, this)
        this.node.on(cc.Node.EventType.TOUCH_END, this.handleTouchEnd, this)
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.handleTouchEnd, this)
    }

    handleTouchStart(e) {
        cc
            .tween(this.node)
            .stop()
    }

    handleTouchMove(e) {
        const { x, y } = e.touch.getDelta()
        this.node.x += x
        this.node.y += y
    }

    handleTouchEnd(e) {
        console.log('touch end')
    }

    handleTouchCancel(e) {
        console.log('touch cancel')
    }

    walkAlongThePath(path) {
        let curTween = cc.tween(this.node)

        path.forEach(n => {
            curTween = curTween.to(0.5, {
                position: n.getPosition()
            })
        })

        curTween.start()
    }

    // update (dt) {}
}
